package com.homedo.odin.solution.controller.common;

import com.homedo.core.common.base.controller.BaseController;
import com.homedo.core.common.base.dto.Meta;
import com.homedo.core.common.base.dto.ResultData;
import com.homedo.odin.solution.contract.pc.EarningReq;
import com.homedo.odin.solution.contract.pc.GetFreezeReq;
import com.homedo.odin.solution.contract.pc.GetFreezeResp;
import com.homedo.odin.solution.contract.pc.GetProfitReq;
import com.homedo.odin.solution.contract.pc.GetProfitResp;
import com.homedo.odin.solution.contract.pc.PayHebiReq;
import com.homedo.odin.solution.service.bizservice.personal.CommonBizService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import javax.servlet.http.HttpServletResponse;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: donglibing
 * @date: 2018/3/6 14:39
 * @Description:
 */
@Api(description = "公共资源", tags = {"PC_Common"}, produces = MediaType.APPLICATION_JSON_VALUE)
@RestController
@RequestMapping("/common")
public class CommonController extends BaseController<CommonBizService> {

    @ApiOperation(value = "下载打包", notes = "下载打包", httpMethod = "GET")
    @GetMapping(value = "/downZip")
    public void downZip(@ApiParam(value = "文件url", required = true) @RequestParam String docurl,
            @ApiParam(value = "自定义文件名字", required = false) @RequestParam(required = false) String fileName,
            HttpServletResponse response) throws Exception {
        baseService.downZip(docurl, response, fileName);
    }

    @ApiOperation(value = "支付河币扣款", notes = "方案支付河币扣款", httpMethod = "POST")
    @PostMapping(value = "/pay")
    public ResultData payHebi(@RequestBody PayHebiReq req) {
        baseService.payHebi(req);
        return ResultData.newInstance(Meta.CODE_200, "支付河币操作完成");
    }

    @ApiOperation(value = "支付河币入账", notes = "方案支付河币入账", httpMethod = "POST")
    @PostMapping(value = "/earning")
    public ResultData earning(@RequestBody EarningReq req) {
        baseService.earning(req);
        return ResultData.newInstance(Meta.CODE_200, "支付河币入账成功");
    }

    @ApiOperation(value = "个人收益", notes = "个人收益", httpMethod = "GET", response = GetProfitResp.class)
    @GetMapping(value = "/profits")
    public ResultData profits(@ModelAttribute("req") GetProfitReq req) {
        GetProfitResp resp = baseService.getProfitList(req);
        return ResultData.newInstance(Meta.CODE_200, resp);
    }

    @ApiOperation(value = "查询冻结信息", notes = "查询冻结信息", httpMethod = "GET", response = GetFreezeResp.class)
    @GetMapping(value = "/freeze")
    public ResultData freeze(@ModelAttribute("req") GetFreezeReq req) {
        GetFreezeResp resp = baseService.getFreeze(req);
        return ResultData.newInstance(Meta.CODE_200, resp);
    }
}
